bigglm.RODBC<-function(formula, data, family = gaussian(),
                       tablename, ..., chunksize=5000){
  terms<-terms(formula)
  modelvars<-all.vars(formula)	
  dots<-as.list(substitute(list(...)))[-1]
  dotvars<-unlist(lapply(dots,all.vars))
  vars<-unique(c(modelvars,dotvars))
  # The commented sql below is only compatible with MySQL. Specifically "limit 1". 
  # Most ohter sql implementations would be "select top 1 * from ",tablename
  # Oracle would need something different.
  # My fix below just uses the modelvars directly.  
  # This means we don't need to query the database for the column headings.  
  # tablerow<-sqlQuery(data, paste("select * from ",tablename," limit 1"))  
  # tablevars<-vars[vars %in% names(tablerow)]
  query<-paste("select ",paste(modelvars,collapse=", ")," from ",tablename)
  result<-odbcQuery(data, query)
  got<-0
  chunk<-function(reset=FALSE){
    if(reset){
      if(got>0){
        result<<-odbcQuery(data,query)
        got<<-0
      }
      return(TRUE)
    }
    rval<-sqlGetResults(data,max=chunksize)	
    got<<-got+NROW(rval)
    if (!is.data.frame(rval) || NROW(rval)==0) 
      return(NULL)
    return(rval)
  }
  rval<-bigglm(formula, data=chunk, family=family, ...)
  rval$call<-sys.call()
  rval$call[[1]]<-as.name(.Generic)
  rval
}

		
